<?php

require_once( 'peachpie.php' );

if( getVar( 'username', 'POST' ) ) {
  $username = getVar( 'username', 'POST' );
  $password = sha1( getVar( 'password', 'POST' ) );


  if( User::authenticateUser( $username, $password ) ) {
    $user = User::getUserByUsername( $username );
    $_SESSION['message'] = 'Login successful!  You are signed in as '. $user->username;
    $_SESSION['userid'] = $user->userid;
    header( "Location: home.php" );
  } else {
    $message = '<span class="error">Your username and/or password could not be verified.  Please ensure your CAPS lock is
      not on, and try again.  If you continue to have problems, please contact your system administrator.</span><br /><br />';
  }

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>
  <title>PeachPie CMS</title>
  <link rel="stylesheet" type="text/css" href="include/style.css" />
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  <meta name="robots" content="none" />
  <script type="text/javascript" src="include/javascript.js"></script>
</head>

<body>

  <div class="wrapper">

    <div class="header" id="nav">
      <div class="signon">You are signed in as: <?php echo $user->username; ?></div>
      <ul>

<?php

echo '
        <li><a href="'. $platform[ 'FILE' ][ 'url' ] .'/home.php" rel="self">Home</a></li>
        <li><a href="'. $platform[ 'FILE' ][ 'url' ] .'/blog.php" rel="self">Blog</a></li>
        <li><a href="'. $platform[ 'FILE' ][ 'url' ] .'/photos.php" rel="self">Photos</a></li>';


if( checkadmin() ) {
echo '
        <li><a href="'. $platform[ 'FILE' ][ 'url' ] .'/admin.php" rel="self">Admin</a></li>';
}

echo '
        <li><a href="'. $platform[ 'FILE' ][ 'url' ] .'/signout.php" rel="self">Sign Out</a></li>';
?>

      </ul>
    </div>

    <div class="logo">
      <div class="inner"></div>
    </div>

    <div class="content">

      <div class="message">
        <?php echo getVar( 'message', 'SESSION' ); ?>
      </div>



      <div class="reset"></div>
    </div>

    <div class="footer">
      PeachPie Content Management System &copy; 2006<br />
      PeachPie is licensed under the GPLv3, is redistributable, and pieces of PeachPie 
      may be used in other software products.
    </div>

</body>
</html>